package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.Organ;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * 预约
 *
 * @author 王睿智<geekrize@gmail.com>
 */
@Entity
public class Reserve extends AbstractVersionEntity {

    private static final long serialVersionUID = -5346693272930359465L;

    @Column(nullable = false, updatable = false)
    private String sn; // 单据编号

    @OrderBy("createTime DESC")
    @OneToMany(mappedBy = "owner")
    protected Set<ReserveEntry> entries; // 分录

    @JSONField(serialize = false)
    @ManyToOne
    private Organ organ; // 所属机构

    @Column(nullable = false)
    private Integer state = 0; // -1 标记删除 0 普通状态 1 已接爱 2 已拒绝

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", nullable = false, insertable = false, updatable = false)
    private Date createTime; // 创建时间

    @Transient
    private String organId;
    @Transient
    private String organName;

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Set<ReserveEntry> getEntries() {
        return entries;
    }

    public void setEntries(Set<ReserveEntry> entries) {
        this.entries = entries;
    }

    public Organ getOrgan() {
        return organ;
    }

    public void setOrgan(Organ organ) {
        this.organ = organ;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getOrganId() {
        if (organId != null) {
            return organId;
        }

        if (organ != null) {
            organId = organ.getId();
        }

        return organId;
    }

    public void setOrganId(String organId) {
        this.organId = organId;
    }

    public String getOrganName() {
        if (organName != null) {
            return organName;
        }

        if (organ != null) {
            organName = organ.getName();
        }

        return organName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }
}
